package logic

import (
	"car_srv/car"
	"car_srv/internal/svc"
	"car_srv/models"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品发布
func (l *GoodsAddLogic) GoodsAdd(in *car.GoodsAddRequest) (*car.GoodsAddResponse, error) {
	good := models.Good{
		GoodsTitle:  in.GoodsTitle,
		GoodsImage:  in.GoodsImage,
		GoodsInfo:   in.GoodsInfo,
		GoodsPrice:  float64(in.GoodsPrice),
		GoodsStock:  in.GoodsStock,
		GoodsStatus: in.GoodsStatus,
	}
	if err := good.Create(); err != nil {
		logx.Error("商品发布失败", err)
		return nil, err
	}

	return &car.GoodsAddResponse{
		Id: int64(good.ID),
	}, nil
}
